class PlacesController < ApplicationController
  
  before_filter :login_required
  
  def new
    @place = Place.new
    @countries = Country.find(:all)
    # país seleccionado por defecto
    @selected_country = Country.find(:first, :select => 'id', :conditions => { :name => "España" })
    respond_to do |format|
      format.html
      format.js
    end
  end
  
  def create
    @place = Place.create(params[:place])
    respond_to do |format|
      format.html
      format.js
    end
  end
  
  def list
    respond_to do |format|
      format.html
      format.js
    end
  end
  
  def show
    
  end
  
  def destroy
    place = Place.find(params[:id])
    place.destroy
    respond_to do |format|
      format.js
      format.html
    end
  end
  
  
  def update
    place = Place.find(params['place']['id'])
    place.update_attributes(params[:place]) 
    respond_to do |format|
      format.js
      format.html
    end    
  end
  
  
  # AJAX actions
  def load_update_form
    @place = Place.find(params[:id])
    @countries = Country.find(:all)
    # país seleccionado por defecto
    @selected_country = Country.find(:first, :select => 'id', :conditions => { :name => "España" })
  end

  def ignore_map
    
  end
  
  def get_map
    respond_to do |format|
      format.js
    end
  end
  
  
end
